package com.xian.scala.wc

import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.api.scala._

object MyWC {
  def main(args: Array[String]): Unit = {
    val file = args(0);
    println("传入文件为:"+file)
    val env = ExecutionEnvironment.getExecutionEnvironment
    //val file = env.readTextFile("E:/test/wc.txt")
    //通过参数传入文件
    val lines = env.readTextFile(args(0))
    val words = lines.flatMap(_.split(" "))
    val kOne = words.map((_, 1))
    val kGOne = kOne.groupBy(0)
    val kSum = kGOne.sum(1)
    //打印
    kSum.print()



  }

}
